package com.qf.flash.ui.circle.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.qf.flash.R;
import com.qf.flash.model.HotListBean;
import com.qf.flash.utils.ImageLoader;
import com.qf.flash.widget.RatingBarView;
import com.qf.flashlib.adapter.BaseRViewItem;
import com.qf.flashlib.adapter.RViewHolder;
import com.zhy.view.flowlayout.FlowLayout;
import com.zhy.view.flowlayout.TagAdapter;
import com.zhy.view.flowlayout.TagFlowLayout;

import java.text.DecimalFormat;
import java.util.List;

import butterknife.OnClick;

/**
 * 2020/2/24 16:38
 */
public class HotListItem extends BaseRViewItem<HotListBean> {


    @Override
    public int getItemLayout() {
        return R.layout.item_hot_list;
    }

    @Override
    public void convert(RViewHolder holder, HotListBean entity, int position, int itemSize) {
        TextView tvRank = holder.getView(R.id.tv_rank);
        ImageView ivRank = holder.getView(R.id.iv_rank);
        ImageView ivCover = holder.getView(R.id.iv_cover);
        RatingBarView rbvStar = holder.getView(R.id.rbv_star);
        TagFlowLayout tagFlowLayout = holder.getView(R.id.tfl_tag);
        switch (position) {
            case 0:
                ivRank.setVisibility(View.VISIBLE);
                ivRank.setImageResource(R.mipmap.number_one);
                break;
            case 1:
                ivRank.setVisibility(View.VISIBLE);
                ivRank.setImageResource(R.mipmap.number_two);
                break;
            case 2:
                ivRank.setVisibility(View.VISIBLE);
                ivRank.setImageResource(R.mipmap.number_three);
                break;
            default:
                ivRank.setVisibility(View.INVISIBLE);
                tvRank.setText("" + (position + 1));
                break;
        }

        ImageLoader.load(holder.getmConvertView().getContext(), entity.getImage(), ivCover);

        holder.setText(R.id.tv_title,entity.getName());

        DecimalFormat df = new DecimalFormat("#0.0");
        String str = df.format(entity.getResponseScole());
        holder.setText(R.id.tv_big_num,str);
        holder.setText(R.id.tv_discuss,entity.getResponseCount()+"评论");
//        rbvStar.setStar((int) Math.round(hotListBean.getResponseScole()), false);
        rbvStar.setStar((int) Math.round(entity.getResponseScole()), false);

        initTag(holder.getmConvertView().getContext(),tagFlowLayout,entity.getTags());
    }

    @OnClick(R.id.iv_cover)
    public void onViewClicked() {
    }


    private void initTag(Context context,TagFlowLayout tflTag, List<String> tags) {
        tflTag.setAdapter(new TagAdapter<String>(tags) {
            @Override
            public View getView(FlowLayout parent, int position, String s) {
                TextView tv_hot = (TextView) LayoutInflater.from(context).inflate(R.layout.item_tag, tflTag, false);
                tv_hot.setText(s);
                return tv_hot;
            }
        });

    }
}
